package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.lang.Snowflake;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Familytree;
import com.ruoyi.system.service.IFamilytreeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 直系亲人报告Controller
 *
 * @author ruoyi
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/familytree")
public class FamilytreeController extends BaseController
{
    @Autowired
    private IFamilytreeService familytreeService;


    /**
     * 查询直系亲人报告列表
     */
    @RequiresPermissions("system:familytree:list")
    @GetMapping("/list")
    public TableDataInfo list(Familytree familytree)
    {
        startPage();

        List<Familytree> list = familytreeService.selectFamilytreeList(familytree);
        return getDataTable(list);
    }

    /**
     * 导出直系亲人报告列表
     */
    @RequiresPermissions("system:familytree:export")
    @Log(title = "直系亲人报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Familytree familytree)
    {
        List<Familytree> list = familytreeService.selectFamilytreeList(familytree);
        ExcelUtil<Familytree> util = new ExcelUtil<Familytree>(Familytree.class);
        util.exportExcel(response, list, "直系亲人报告数据");
    }

    /**
     * 获取直系亲人报告详细信息
     */
    @RequiresPermissions("system:familytree:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(familytreeService.selectFamilytreeById(id));
    }

    /**
     * 新增直系亲人报告
     */
    @RequiresPermissions("system:familytree:add")
    @Log(title = "直系亲人报告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Familytree familytree)
    {
        return toAjax(familytreeService.insertFamilytree(familytree));
    }

    /**
     * 修改直系亲人报告
     */
    @RequiresPermissions("system:familytree:edit")
    @Log(title = "直系亲人报告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Familytree familytree)
    {
        return toAjax(familytreeService.updateFamilytree(familytree));
    }

    /**
     * 删除直系亲人报告
     */
    @RequiresPermissions("system:familytree:remove")
    @Log(title = "直系亲人报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(familytreeService.deleteFamilytreeByIds(ids));
    }
}
